<?xml version="1.0"?>
<ScatterFile xmlns="http://schemas.microsoft.com/netmf/ScatterfileSchema.xsd">

    <!-- STM32F4 with 1M Flash, 128k SRAM, and 64k CCM -->

    <Set Name="Valid" Value="false"/>

    <!-- ################################################################################ -->


    <!-- CCM -->
    <Set Name="Stack_Bottom"            Value="0x10000000"/>
    <Set Name="Stack_Top"               Value="0x10003FF8"/>
    
    <Set Name="RAM_Start"               Value="0x10004000"/>
    
    <!-- SRAM -->
    <Set Name="Heap_Begin"              Value="0x20010000"/>
    <Set Name="Heap_End"                Value="0x20017FF8"/>

    <Set Name="Custom_Heap_Begin"       Value="0x20018000"/>
    <Set Name="Custom_Heap_End"         Value="0x2001FFF8"/>

    <If Name="TARGETLOCATION" In="FLASH">

        <Set Name="Code_BaseAddress"  Value="0x08000000"/>
        <Set Name="Code_Size"         Value="0x0000C000"/>
        <Set Name="Valid"             Value="true"/>

    </If>

    <If Name="TARGETLOCATION" In="RAM">

        <Set Name="Code_BaseAddress"  Value="0x20000000"/> 
        <Set Name="Code_Size"         Value="0x0000C000"/>
        <Set Name="Valid"             Value="true"/>
        
    </If>


    <!-- ################################################################################ -->

    <If Name="Valid" Value="false">
        <Error Message="Configuration not recognized"/>
    </If>

    <LoadRegion Name="LR_%TARGETLOCATION%" Base="%Code_BaseAddress%" Options="ABSOLUTE" Size="%Code_Size%">

        <ExecRegion Name="ER_%TARGETLOCATION%" Base="%Code_BaseAddress%" Options="FIXED" Size="">
            <FileMapping Name="FirstEntry.obj"   Options="(+RO, +FIRST)" /> <!-- the entry pointer section goes into this region -->
            <FileMapping Name="*" Options="(SectionForBootstrapOperations)" />
            <FileMapping Name="*" Options="(+RO-CODE)" />
            <FileMapping Name="*" Options="(+RO-DATA)" />
        </ExecRegion>

        <ExecRegion Name="ER_RAM_RO" Base="%RAM_Start%" Options="ABSOLUTE" Size="">
            <!-- Flash programming from Flash is save on STM32 -->
            <!-- No need to place Flash programming code in RAM -->
            <!-- <FileMapping Name="*" Options="(SectionForFlashOperations)" /> -->
        </ExecRegion>

        <ExecRegion Name="ER_RAM_RW" Base="+0" Options="ABSOLUTE" Size="">
            <FileMapping Name="*" Options="(+RW-DATA, +ZI)" />
        </ExecRegion>

        <ExecRegion Name="ER_HEAP_BEGIN" Base="%Heap_Begin%" Options="ABSOLUTE" Size="UNINIT">
            <FileMapping Name="*" Options="(SectionForHeapBegin)" />
        </ExecRegion>

        <!-- everything between heapbegin and heapend will be allocated for a heap -->

        <ExecRegion Name="ER_HEAP_END" Base="%Heap_End%" Options="ABSOLUTE" Size="UNINIT">
            <FileMapping Name="*" Options="(SectionForHeapEnd)" />
        </ExecRegion>

        <ExecRegion Name="ER_CUSTOM_HEAP_BEGIN" Base="%Custom_Heap_Begin%" Options="ABSOLUTE" Size="UNINIT">
          <FileMapping Name="*" Options="(SectionForCustomHeapBegin)" />
        </ExecRegion>

        <!-- everything between heapbegin and heapend will be allocated for the unmanaged SimpleHeap -->

        <ExecRegion Name="ER_CUSTOM_HEAP_END" Base="%Custom_Heap_End%" Options="ABSOLUTE" Size="UNINIT">
          <FileMapping Name="*" Options="(SectionForCustomHeapEnd)" />
        </ExecRegion>

        <!-- this must go last here to provide a low water mark on the stack -->

        <ExecRegion Name="ER_STACK_BOTTOM" Base="%Stack_Bottom%" Options="ABSOLUTE" Size="UNINIT">
            <FileMapping Name="*" Options="(SectionForStackBottom)" />
        </ExecRegion>
	    
        <ExecRegion Name="ER_STACK_TOP" Base="%Stack_Top%" Options="ABSOLUTE" Size="UNINIT">
            <FileMapping Name="*" Options="(SectionForStackTop)" />
        </ExecRegion>

    </LoadRegion>

</ScatterFile>
